package chapter6_1_LockSupport;

import java.util.concurrent.locks.LockSupport;

/**
 * LockSupport 类与每个使用它的线程都会关联一个许可证，在默认情况下调用
 * LockSupport 类的方法的线程是不持有许可证的
 * @author huayuhao
 * @date 2020/12/16 16:59
 */
public class LockSupportTest {

    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(() ->{
            String name = Thread.currentThread().getName();
            System.out.println(name + " begin park");
            LockSupport.park();// 如果调用park的线程已经获得了关联的许可证,就会立即返回
            System.out.println(name + " end park");
        },"A");
        thread.start();

        Thread.sleep(1000);

        System.out.println(thread.getName() + " begin unpark");

        LockSupport.unpark(thread);

    }
}
